package com.oop.example.work.esport;

import com.oop.example.processing.ErrorException;
import com.oop.example.processing.msdoc.LengthComparator;
import com.oop.example.utils.Utils;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Properties;

/**
 *
 * @author -
 */
public class LabelChecker {

    Properties ld = Utils.getLabelDictionary();
    Properties config = Utils.getConfig();

    public void check(String prepared) throws ErrorException {
        int start = prepared.indexOf("</b>");
        prepared = prepared.substring(start);

        prepared =
                prepared.replaceAll("\\,", " , ").
                replaceAll("\\.", " . ").
                replaceAll("\\:", " : ").
                replaceAll("\\+", " + ").
                replaceAll("\\;", " ; ");

        List<String> list = new ArrayList<String>();
        for (String str : ld.stringPropertyNames()) {
            list.add(str);
        }
        Collections.sort(list, new LengthComparator());
        for (String s : list) {
            String s1 = " " + s + " ";
            if (prepared.contains(s1)) {

                if (config.get("ERROR_EXCEPTION").toString().equalsIgnoreCase("true")) {
                    throw new ErrorException("Найдено подозрение на помету :" + s, prepared.indexOf(s1) + start);
                }
            }
        }
    }
}
